import heapq
class Solution(object):
    def maxAverageRatio(self, classes, extraStudents):
        st = [[(x - y) / ((y + 1) * y), x, y] for x, y in classes]
        k = 0
        heapq.heapify(st)
        while k < extraStudents:
            k += 1
            _, x, y = heapq.heappop(st)
            x += 1
            y += 1
            heapq.heappush(st, [(x - y) / ((y + 1) * y), x, y])
        n = len(st)
        return sum([x / y for _, x, y in st]) / n